// Battery组件模拟数据 - 只包含Data类型，所有数值为正整数

interface EnergyDataPoint {
  label: string;
  solar: number; // 太阳能数据 (正整数)
  grid: number; // 电网相关数据 (正整数)
  home: number; // 家庭用电数据 (正整数)
}

interface TimeSeriesData {
  timePoints: string[];
  energyData: EnergyDataPoint[];
}

// Day数据 - 24小时，2小时间隔，共12个数据点
const dayData: TimeSeriesData = {
  timePoints: [
    "02:00",
    "04:00",
    "06:00",
    "08:00",
    "10:00",
    "12:00",
    "14:00",
    "16:00",
    "18:00",
    "20:00",
    "22:00",
    "24:00"
  ],
  energyData: [
    { label: "02:00", solar: 0, grid: 1, home: 1 }, // 夜间低谷
    { label: "04:00", solar: 0, grid: 1, home: 1 }, // 深夜最低
    { label: "06:00", solar: 0, grid: 1, home: 2 }, // 早晨开始
    { label: "08:00", solar: 1, grid: 1, home: 2 }, // 早高峰
    { label: "10:00", solar: 2, grid: 0, home: 1 }, // 上午
    { label: "12:00", solar: 3, grid: 0, home: 1 }, // 中午峰值
    { label: "14:00", solar: 3, grid: 0, home: 1 }, // 下午
    { label: "16:00", solar: 2, grid: 0, home: 1 }, // 下午
    { label: "18:00", solar: 1, grid: 1, home: 3 }, // 晚高峰开始
    { label: "20:00", solar: 0, grid: 2, home: 3 }, // 晚高峰
    { label: "22:00", solar: 0, grid: 2, home: 3 }, // 晚高峰峰值
    { label: "24:00", solar: 0, grid: 1, home: 1 } // 夜间回落
  ]
};

// Week数据 - 7天，每天一个数据点
const weekData: TimeSeriesData = {
  timePoints: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  energyData: [
    { label: "Mon", solar: 45, grid: 5, home: 15 }, // 周一工作日
    { label: "Tue", solar: 48, grid: 4, home: 16 }, // 周二
    { label: "Wed", solar: 42, grid: 5, home: 15 }, // 周三
    { label: "Thu", solar: 50, grid: 6, home: 17 }, // 周四
    { label: "Fri", solar: 38, grid: 7, home: 18 }, // 周五
    { label: "Sat", solar: 55, grid: 3, home: 20 }, // 周六周末
    { label: "Sun", solar: 52, grid: 4, home: 19 } // 周日
  ]
};

// Month数据 - 31天，每天一个数据点
const monthData: TimeSeriesData = {
  timePoints: [
    "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
    "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
    "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"
  ],
  energyData: [
    { label: "1", solar: 45, grid: 5, home: 15 },
    { label: "2", solar: 48, grid: 4, home: 16 },
    { label: "3", solar: 42, grid: 6, home: 14 },
    { label: "4", solar: 50, grid: 3, home: 17 },
    { label: "5", solar: 38, grid: 5, home: 15 },
    { label: "6", solar: 55, grid: 2, home: 18 },
    { label: "7", solar: 52, grid: 4, home: 16 },
    { label: "8", solar: 45, grid: 5, home: 15 },
    { label: "9", solar: 58, grid: 3, home: 17 },
    { label: "10", solar: 40, grid: 6, home: 14 },
    { label: "11", solar: 48, grid: 4, home: 16 },
    { label: "12", solar: 42, grid: 5, home: 15 },
    { label: "13", solar: 55, grid: 2, home: 18 },
    { label: "14", solar: 38, grid: 6, home: 14 },
    { label: "15", solar: 50, grid: 4, home: 16 },
    { label: "16", solar: 45, grid: 5, home: 15 },
    { label: "17", solar: 58, grid: 3, home: 17 },
    { label: "18", solar: 35, grid: 7, home: 18 },
    { label: "19", solar: 48, grid: 4, home: 16 },
    { label: "20", solar: 42, grid: 5, home: 15 },
    { label: "21", solar: 55, grid: 2, home: 18 },
    { label: "22", solar: 38, grid: 6, home: 14 },
    { label: "23", solar: 50, grid: 4, home: 16 },
    { label: "24", solar: 45, grid: 5, home: 15 },
    { label: "25", solar: 58, grid: 3, home: 17 },
    { label: "26", solar: 35, grid: 7, home: 18 },
    { label: "27", solar: 48, grid: 4, home: 16 },
    { label: "28", solar: 42, grid: 5, home: 15 },
    { label: "29", solar: 55, grid: 2, home: 18 },
    { label: "30", solar: 38, grid: 6, home: 14 },
    { label: "31", solar: 50, grid: 4, home: 16 }
  ]
};

// Year数据 - 12个月，每月一个数据点
const yearData: TimeSeriesData = {
  timePoints: [
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  ],
  energyData: [
    { label: "Jan", solar: 1200, grid: 120, home: 350 }, // 冬季，太阳能少
    { label: "Feb", solar: 1350, grid: 100, home: 320 }, // 春节期间用电高
    { label: "Mar", solar: 1500, grid: 90, home: 310 }, // 春季开始
    { label: "Apr", solar: 1800, grid: 80, home: 300 }, // 春季，太阳能增加
    { label: "May", solar: 2100, grid: 60, home: 290 }, // 春末夏初
    { label: "Jun", solar: 2400, grid: 40, home: 380 }, // 夏季开始，空调用电增加
    { label: "Jul", solar: 2600, grid: 30, home: 420 }, // 夏季高峰，太阳能最多
    { label: "Aug", solar: 2500, grid: 35, home: 410 }, // 夏季持续
    { label: "Sep", solar: 2200, grid: 50, home: 370 }, // 秋季开始
    { label: "Oct", solar: 1900, grid: 70, home: 330 }, // 秋季
    { label: "Nov", solar: 1400, grid: 100, home: 320 }, // 晚秋
    { label: "Dec", solar: 1100, grid: 120, home: 360 } // 冬季，供暖用电
  ]
};

// Analysis数据生成器 - 基于原数据创建优化建议数据
const generateAnalysisData = (originalData: TimeSeriesData): TimeSeriesData => {
  return {
    timePoints: originalData.timePoints,
    energyData: originalData.energyData.map(point => ({
      label: point.label,
      solar: Math.round(point.solar * 1.1), // 增加10%太阳能利用
      grid: Math.round(point.grid * 0.85), // 减少15%电网依赖
      home: point.home // 家庭用电保持不变
    }))
  };
};

// 生成所有时间维度的Analysis数据
const dayAnalysisData = generateAnalysisData(dayData);
const weekAnalysisData = generateAnalysisData(weekData);
const monthAnalysisData = generateAnalysisData(monthData);
const yearAnalysisData = generateAnalysisData(yearData);

// 主要导出的模拟数据结构
export const mockData = {
  data: {
    day: dayData,
    week: weekData,
    month: monthData,
    year: yearData
  },
  analysis: {
    day: dayAnalysisData,
    week: weekAnalysisData,
    month: monthAnalysisData,
    year: yearAnalysisData
  }
};

// 获取指定时间维度和数据类型的数据
export function getMockData(
  timeScope: "day" | "week" | "month" | "year",
  dataType: "data" | "analysis" = "data"
) {
  return mockData[dataType][timeScope];
}

// 计算汇总数据
export function calculateTotals(data: EnergyDataPoint[]) {
  return data.reduce(
    (acc, point) => ({
      totalSolar: acc.totalSolar + point.solar,
      totalGrid: acc.totalGrid + point.grid,
      totalHome: acc.totalHome + point.home
    }),
    { totalSolar: 0, totalGrid: 0, totalHome: 0 }
  );
}

// 计算饼状图数据 (假设这里是Battery充放电来源分布)
export function calculatePieData(data: EnergyDataPoint[]) {
  const totals = calculateTotals(data);
  const total = totals.totalSolar + totals.totalGrid;

  return [
    {
      name: "From Solar",
      value: totals.totalSolar,
      percentage: Math.round((totals.totalSolar / total) * 100) + "%",
      color: "#fcc419"
    },
    {
      name: "From Grid",
      value: totals.totalGrid,
      percentage: Math.round((totals.totalGrid / total) * 100) + "%",
      color: "#9ca3af"
    }
  ];
}
